//
//  UIScrollView+TTWholeCapture.m
//  Pods
//
//  Created by caoxiaobo on 2017/6/26.
//
//

#import "UIScrollView+TTWholeCapture.h"

@implementation UIScrollView (TTWholeCapture)

- (nullable UIImage *)ia_scrollViewCapture
{
    UIImage *captureImage = nil;
    UIScrollView *scrollView = self;
    UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, scrollView.opaque, 0.0);
    {
        CGPoint savedContentOffset = scrollView.contentOffset;
        CGRect savedFrame = scrollView.frame;
        scrollView.contentOffset = CGPointZero;
        scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
        [scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
        captureImage = UIGraphicsGetImageFromCurrentImageContext();
        scrollView.contentOffset = savedContentOffset;
        scrollView.frame = savedFrame;
    }
    UIGraphicsEndImageContext();
    return captureImage;
}

@end
